package com.yyz.controller;

import com.yyz.dao.DoorMapper;
import com.yyz.pojo.Door;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

@Controller
public class TestController {

    //测试springmvc
    @RequestMapping("/hello")
    public String hello(){
        return "test";
    }

    //测试mybatis开发环境
    public static void main(String[] args) throws IOException {
        //1.读取mybatis-config.xml核心文件
        InputStream in = Resources.getResourceAsStream("mybatis/mybatis-config.xml");
        //2、创建SqlSessionFactory对象
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in);
        //3、创建SqlSession对象
        SqlSession session = factory.openSession();
        //4、获取DoorMapper接口的实现类对象
        DoorMapper doorMapper = session.getMapper(DoorMapper.class);
        //5、调用findAll方法查询所有门店信息
        List<Door> doorList = doorMapper.findAll();
        //6、遍历doorList集合，打印门店信息
        for (Door door : doorList) {
            System.out.println(door);
        }

    }
}
